
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	
	<xsl:template match="mensagem">
		<xsl:copy>
			<xsl:copy-of select="@remetente"/>
			<xsl:copy-of select="@destinatario"/>
			<xsl:copy-of select="@id"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>
	
	<xsl:template match="resposta/livro">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates select="isbn"/>
			<xsl:apply-templates select="dono"/>			
		</xsl:copy>
	</xsl:template>	
	
	<xsl:template match="/mensagem/solicitacao">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>		
	
	<xsl:template match="solicitacao">
		<solicitacoes>
			<xsl:copy-of select="@*"/>		
			<xsl:attribute name="remetente"><xsl:value-of select="//de[1]/text()"/></xsl:attribute>
			<xsl:attribute name="destinatario"><xsl:value-of select="//para[1]/text()"/></xsl:attribute>			
			<xsl:apply-templates/>
		</solicitacoes>
	</xsl:template>		
	
	<xsl:template match="emprestimo">
		<solicitacao>	
			<xsl:attribute name="tipo">emprestimo</xsl:attribute>	
			<xsl:apply-templates select="livro"/>		
		</solicitacao>		
	</xsl:template>	
	
	<xsl:template match="devolucao">
		<solicitacao>	
			<xsl:attribute name="tipo">devolucao</xsl:attribute>	
			<xsl:apply-templates select="livro"/>		
		</solicitacao>		
	</xsl:template>	
	
	<xsl:template match="emprestimo/livro|devolucao/livro">
		<livro>	
			<xsl:attribute name="dono"><xsl:value-of select="dono/text()"/></xsl:attribute>	
			<xsl:attribute name="isbn"><xsl:value-of select="isbn/text()"/></xsl:attribute>				
		</livro>		
	</xsl:template>		
	
	<xsl:template match="*">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>	
</xsl:stylesheet>